package com.xbongbong.pro.statistics.factory;

import com.xbongbong.pro.statistic.enums.ChartTypeEnum;
import com.xbongbong.pro.statistics.strategy.chart.type.ChartTypeStrategyService;
import com.xbongbong.pro.statistics.strategy.chart.type.impl.ChartStrategyServiceImpl;
import com.xbongbong.pro.statistics.strategy.chart.type.impl.DataQueryTableStrategyServiceImpl;
import com.xbongbong.pro.statistics.strategy.chart.type.impl.DataStatisticsTableStrategyServiceImpl;
import com.xbongbong.pro.statistics.strategy.chart.type.impl.TargetChartStrategyServiceImpl;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 图表类型解析工厂
 * @author xinpeng.jiang
 * @date 2021/11/1 14:01
 * @version 1.0
 * @since V1.0
 */
@Component
public class ChartTypeAnalysisFactory {
    
    private static final Map<Integer, ChartTypeStrategyService> CHART_TYPE_STRATEGY_SERVICE_MAP = new HashMap<>(11);

    @Resource
    private DataQueryTableStrategyServiceImpl dataQueryTableStrategyService;
    @Resource
    private ChartStrategyServiceImpl chartStrategyService;
    @Resource
    private TargetChartStrategyServiceImpl targetChartStrategyService;
    @Resource
    private DataStatisticsTableStrategyServiceImpl dataStatisticsTableStrategyService;

    @PostConstruct
    public void init() {
        // 添加的时候别忘改下hashmap初始值
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.DATA_QUERY_TABLE.getCode(), dataQueryTableStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.PK_CUSTOM.getCode(), dataQueryTableStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.BAR_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.BROADWISE_BAR_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.LINE_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.AREA_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.RADAR_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.PIE_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.BIAXIAL_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.TARGET_CHART.getCode(), targetChartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.SECOND_TARGET_CHART.getCode(), targetChartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.DATA_STATISTICS_TABLE.getCode(), dataStatisticsTableStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.MAP_CUSTOM.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.SCATTER_CHART.getCode(), chartStrategyService);
        CHART_TYPE_STRATEGY_SERVICE_MAP.put(ChartTypeEnum.FUNNEL.getCode(), chartStrategyService);
    }

    public static ChartTypeStrategyService getChartTypeStrategyService(Integer chartType) {
        if (chartType == null) {
            return null;
        }
        return CHART_TYPE_STRATEGY_SERVICE_MAP.get(chartType);
    }
}
